<template> 
<!-- 消费记录 -->
    <div class="consume_contentBox">
        <block v-if="getconsumeList.length">
            <div class="box" v-for="(item,index) in getconsumeList" :key="index">
            <div class="box_icon">
                <img :src="item.cover" alt="">
            </div>
            <div class="box_banner">
                <div class="box_banner_ins">
                    <div class="box_banner_ins_til">{{item.title}}</div>
                </div>
                <div class="box_banner_pink">
                    <div class="box_banner_pink_lump">{{item.created_at}}</div>
                    <!-- <div class="box_banner_pink_lump">  12</div> -->
                </div>
                <div class="box_banner_text">
                    ￥{{item.price}}
                </div>
            </div>
            </div>
        </block>
        <ListEmpty v-else />
    </div>
</template>

<script lang="ts">
import store from '@/store';

import ListEmpty from '@/components/list/listEmpty.vue';
import {
    api,
} from '@/lib/api';

import { Component, Vue } from 'vue-property-decorator';
import { ROUTE_NAME } from '@/lib/constant';
import { Route } from 'vue-router';
import { EMPTY_LIST } from '@/lib/constant';

Component.registerHooks([
    'beforeRouteEnter',
]);

@Component({
    name: 'ShopList',
    components: {
        ListEmpty
    }
})

export default class ShopList extends Vue {
    public title: any = '';

    /** 订单列表 */
    public get wrap() {
        return store.state.shop.consumeList['null'] || {
            list: [],
            loaded: false,
            req: false,
        };
    }
    public get getconsumeList(){
        return this.wrap.list;
    }
    public async getDate(_offset,_forceUpdate) {
        await store.dispatch('shop/getconsumeList', {
            offset: _offset,
            count: 10,
            forceUpdate: _forceUpdate
        });
    }
    public async onReachBottom() {
        this.getDate(this.getconsumeList.length,false);
    }
    public async onPullDownRefresh() {
        this.getDate(0, true);
        wx.stopPullDownRefresh();
    }
    
    public async created() {
        // this.getDate(0,true);
        store.commit('utils/startRequest');
        await Promise.all([
            store.dispatch('shop/getconsumeList', {
                offset: 0,
                count: 10
            }),
        ]);
        store.commit('utils/endRequest');

        window.addEventListener('reachbottom', this.onReachBottom);
        window.addEventListener('pulldownrefresh', this.onPullDownRefresh);
    }
    public beforeDestroy() {
        window.removeEventListener('reachbottom', this.onReachBottom);
        window.removeEventListener('pulldownrefresh', this.onPullDownRefresh);
    }

}
</script>
<style lang="less">
.consume_contentBox{
    width: 100%;
    min-height: 100vh;
    // overflow: hidden;
    // overflow-y: scroll;
    background-color: #F8F8F8;
    .box{
        width: 92%;
        display: flex;
        // justify-content: space-around;
        justify-content: space-evenly;
        background-color: #ffffff;
        border-radius: 10rpx;
        padding: 10rpx 0rpx;
        margin: 0rpx auto;
        .box_icon{
            width: 90rpx;
            height: 90rpx;
            margin-top: 20rpx;
            img{
                width: 90rpx;
                height: 90rpx;
                border-radius: 30rpx;
                background-color: #E6E6E6;
            }
        }
        .box_banner{
            width: 82%;
            height: 120rpx;
            // line-height: 110rpx;
            display: flex;
            justify-content: space-around;
            border-bottom: 1rpx solid #cccccc;
            .box_banner_ins{
                width: 38%;
                font-size: 28rpx;
                color: #000;

                .box_banner_ins_til{
                    height: 110rpx;
                    line-height: 120rpx;
                    font-weight: 600;
                    color: #797979;
                    overflow: hidden;
                    text-overflow:ellipsis;
                    white-space: nowrap;
                }
            }
            .box_banner_pink{
                width: 24%;
                font-size: 20rpx;
                color: silver;
                padding-top: 27rpx;
                // span{
                //     display: inline-block;
                // }
                .box_banner_pink_lump{
                    width: 100%;
                    line-height: 40rpx;
                    text-align: center;
                }
            }
            .box_banner_text{
                width: 30%;
                line-height: 120rpx;
                font-size: 30rpx;
                text-align: right;
                font-weight: 600;
                color: crimson;
            }
        }
    }
}
</style>
